package com.medistat.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.annotations.GenericGenerator;

@Inheritance (strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn (name="person_type", discriminatorType=DiscriminatorType.STRING)
@Entity
public class Person extends StandardPersistentObject {
	
	@Id @GeneratedValue(generator="ID_GENERATOR_FOR_PERSON")
	@GenericGenerator(name="ID_GENERATOR_FOR_PERSON", strategy = "increment")
	private Long id;
	
	private String name;
	private String surname;
	private Boolean active;
	
	//parent - back reference
	@ManyToOne(targetEntity=Department.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})	
	@JoinColumns({ @JoinColumn(name="DepartmentID", referencedColumnName="ID") })	
	@Basic(fetch=FetchType.LAZY)
	private Department department;
	
	//dependent free days
	@OneToMany(mappedBy="person", targetEntity=FreeDay.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.FALSE)	
	private List<FreeDay> listOfFreeDays = new ArrayList<FreeDay>();
	
	//dependent WeekendDutiesInfo 
	@OneToMany(mappedBy="person", targetEntity=WeekendDutiesInfo.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.FALSE)	
	private List<WeekendDutiesInfo> listOfWeekendDutiesInfos = new ArrayList<WeekendDutiesInfo>();
	
	public Long getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	public Boolean getActive() {
		return active;
	}
	public void setActive(Boolean active) {
		this.active = active;
	}
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	public List<FreeDay> getListOfFreeDays() {
		return listOfFreeDays;
	}
	public void setListOfFreeDays(List<FreeDay> listOfFreeDays) {
		this.listOfFreeDays = listOfFreeDays;
	}
	public List<WeekendDutiesInfo> getListOfWeekendDutiesInfos() {
		return listOfWeekendDutiesInfos;
	}
	public void setListOfWeekendDutiesInfos(List<WeekendDutiesInfo> listOfWeekendDutiesInfos) {
		this.listOfWeekendDutiesInfos = listOfWeekendDutiesInfos;
	}
}
